/**
 * 
 */
package cn.pfcg.rally.persistent.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import cn.pfcg.rally.domain.bean.TestPaper;
import cn.pfcg.rally.persistent.dao.TestPaperDAO;

/**
 * @author cxq
 *
 */
public class TestPaperDAOImpl implements TestPaperDAO {

	HibernateTemplate hibernateTemplate;
	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.TestPaperDAO#deleteTestPaper(java.lang.String)
	 */
	
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	
	public void deleteTestPaper(String testNumber) {
		TestPaper testPaper = (TestPaper)hibernateTemplate.find("from TestPaper testPaper " + "where testPaper.testNumber = ?", testNumber).get(0);
		hibernateTemplate.delete(testPaper);
	}

	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.TestPaperDAO#getTestPaperByName(java.lang.String)
	 */
	public TestPaper getTestPaperByName(String name) {
		return (TestPaper)hibernateTemplate.find("from TestPaper testPaper " + "where testPaper.name = ?" , name).get(0);
	}

	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.TestPaperDAO#getTestPaperByNumber(java.lang.String)
	 */
	public TestPaper getTestPaperByNumber(String testNumber) {
		return (TestPaper)hibernateTemplate.find("from TestPaper testPaper " + "where testPaper.testNumber = ?", testNumber).get(0);
	}

	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.TestPaperDAO#saveTestPaper(cn.pfcg.rally.persistent.po.TestPaper)
	 */
	public void saveTestPaper(TestPaper testPaper) {
		hibernateTemplate.save(testPaper);

	}

	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.TestPaperDAO#updateTestPaper()
	 */
	public void updateTestPaper(String testNumber,TestPaper testPaper) {
		TestPaper testPaper1 = (TestPaper)hibernateTemplate.find("from TestPaper testPaper " + "where testPaper.testNumber = ?", testNumber).get(0);
		testPaper.setId(testPaper1.getId());
		hibernateTemplate.update(testPaper);
	}

	public List<TestPaper> getAllTestPaper() {
		return hibernateTemplate.find("from TestPaper");	
	}

	public String getLastTestPaperNumber() {
		// TODO Auto-generated method stub
		return null;
	}

}
